package com.learn.aop;

import com.learn.annotation.Action;
import java.lang.reflect.Method;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

/**
 * @Author:Mark
 * @Description:
 * @Date: Created on 9:46 2018-11-13
 * @Modify by:
 */
@Aspect
@Component
public class LogAspect {
  @Pointcut(value = "@annotation(com.learn.annotation.Action)")
  public void annotationPoinCut(){}

  @After(value = "annotationPoinCut()")
  public void after(JoinPoint joinPoint){
    MethodSignature signature = (MethodSignature)joinPoint.getSignature();
    Method method = signature.getMethod();
    Action action = method.getAnnotation(Action.class);
    System.out.println("注解式被拦截的对象为==========="+action.name());
  }

  @Before("execution(* com.learn.aop.DemoMethodService.*(..))")
  public void before(JoinPoint joinPoint){
    MethodSignature signature = (MethodSignature)joinPoint.getSignature();
    Method method = signature.getMethod();
    System.out.println("方法拦截规则。。。"+method.getName());

  }

}
